<template>
	<view class="homeLayout">
		<view class="banner">
			<swiper indicator-dots indicator-color="rgba(255,255,255,0.5)" indicator-active-color="#fff" autoplay circular>
				<swiper-item v-for="item in bannerList">
					<image :src="item.picurl" mode="aspectFill"></image>
				</swiper-item>
			</swiper>
		</view>
		<view class="notice">
			<view class="left">
				<uni-icons type="sound-filled" size="20" color="#28b389" />
				<text>公告</text>
			</view>
			<view class="center">
				<swiper vertical autoplay interval="1500" duration="300" circular>
					<swiper-item v-for="(item,index) in announcementList" :key="index">{{item.title}}</swiper-item>
				</swiper>
			</view>
			<view class="right">
				<uni-icons type="right" size="16" color="#333" />
			</view>
		</view>
		<view class="select">
			<commmon-title>
				<template #name>每日推荐</template>
				<template #custom>
					<view class="date">
						<uni-icons type="calendar" size="18" color="#28b389" />
						<view class="text">
							<uni-dateformat :date="Date.now()" format="dd日"/>
						</view>
					</view>
				</template>
			</commmon-title>
			<view class="content">
				<scroll-view scroll-x show-scrollbar>
					<view class="box" v-for="(item,index) in dailyRecommendationList" :key="index">
						<image :src="item.smallPicurl" mode="aspectFill"></image>
					</view>
				</scroll-view>
			</view>
		</view>
		<view class="theme">
			<commmon-title>
				<template #name>专题精选</template>
				<template #custom>
					<navigator url="" class="more">More+</navigator>
				</template>
			</commmon-title>
      <view class="content">
         <theme-item v-for="(item,index) in ThematicSelectionList" :key="index" :ThemeItem="item"/>
      </view>
		</view>
	</view>
</template>

<script lang="ts" setup>
	import { onMounted, reactive } from "vue";
  import {
    fetchAnnouncementList,
    fetchBannerList,
    fetchDailyRecommendationList,
    fetchThematicSelectionList
  } from "@/services/http";

  const bannerList = reactive<Awaited<ReturnType<typeof fetchBannerList>>>([])
  const announcementList = reactive<Awaited<ReturnType<typeof fetchAnnouncementList>>>([])
  const dailyRecommendationList = reactive<Awaited<ReturnType<typeof fetchDailyRecommendationList>>>([])
  const ThematicSelectionList = reactive<Awaited<ReturnType<typeof fetchThematicSelectionList>>>([])

	onMounted(async () => {
    bannerList.splice(0, Infinity, ...await fetchBannerList())
    announcementList.splice(0, Infinity, ...await fetchAnnouncementList())
    dailyRecommendationList.splice(0, Infinity, ...await fetchDailyRecommendationList())
    ThematicSelectionList.splice(0, Infinity, ...await fetchThematicSelectionList())
	})
</script>

<style scoped lang="scss">
	.homeLayout {}

	.banner {
		width: 100%;
		padding: 30rpx 0;

		swiper {
			width: 100%;
			height: 340rpx;

			&-item {
				width: 100%;
				height: 100%;
				padding: 0 30rpx;
				box-sizing: border-box;

				image {
					border-radius: 10rpx;
					width: 100%;
					height: 100%;
				}
			}
		}
	}

	.notice {
		width: 690rpx;
		height: 80rpx;
		line-height: 80rpx;
		background-color: #f9f9f9;
		margin: 0 auto;
		border-radius: 80rpx;
		display: flex;

		.left {
			width: 140rpx;
			display: flex;
			align-items: center;
			justify-content: center;

			text {
				color: #28b389;
				font-weight: 600;
				font-size: 28rpx;
			}
		}

		.center {
			flex: 1;

			swiper {
				height: 100%;

				&-item {
					height: 100%;
					font-size: 30rpx;
					color: #666;

					overflow: hidden;
					white-space: nowrap;
					text-overflow: ellipsis;
				}
			}
		}

		.right {
			width: 70rpx;
			display: flex;
			align-items: center;
			justify-content: center;
		}
	}
	
	.select {
		padding-top: 50rpx;
		.date {
			color: #28b389;
			display: flex;
			align-items: center;
			.text {
				margin-left: 5rpx;
			}
		}
		.content {
			width: 720rpx;
			margin-left: 30rpx;
			margin-top: 30rpx;
			scroll-view {
				white-space: nowrap;
				.box {
					width: 200rpx;
					height: 430rpx;
					display: inline-block;
					margin-right: 15rpx;
					image {
						width: 100%;
						height: 100%;
						border-radius: 10rpx;
					}
				}
				.box:last-child {
					margin-right: 30rpx;
				}
			}
		}
	}
	
	.theme {
		padding-top: 50rpx;
		.more {
			font-size: 32rpx;
			color: #888;
		}
		.content {
			margin-top: 30rpx;
			padding: 0 30rpx;
			display: grid;
			gap: 15rpx;
			grid-template-columns: repeat(3,1fr);
		}
	}
</style>